<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <button @click="add">新增arr</button>
    {{arr}}
    <hr>
    <input type="text" v-model="obj.a">
    <input type="text" v-model="obj.b">
    {{obj.a}}
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data() {
        return {
          arr: [1,2,3,4],
          obj: {
            a: 'aa',
            b: 'bb'
          }
        }
      },
      watch: {
        // 深度侦听
        arr: {
          handler(val){
            console.log('arr改变了', val);
          },
          deep: true // 深度侦听 侦听引用类型
        },
       /*  obj: {
          handler(val){
            console.log('obj改变了', val);
          },
          deep: true // 深度侦听 侦听引用类型
        }, */
        // 直接侦听对象的某个属性
        "obj.a"(val){
          console.log('obj的a属性变化了', val);
        }
      },
      methods: {
        add() {
          this.arr.push(this.arr.length+1)
        }
      },
    })
    app.mount('#app')
  </script>
</body>

</html>